

app.controller('SwitchCtrledit', function SwitchCtrl($scope,SwitchFactory,$location,$http) {
	
	$scope.message =null;
	function getParameterByName(name) {
	name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
	var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
	results = regex.exec(location.search);
	return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
		    }
$scope.id= getParameterByName("id");
$scope.url="http://194.90.90.222:8080/api/getdirectory";
console.log($scope.id);
$http.post($scope.url,
	"{\"extention\": "+ $scope.id +" }").success(loadDirectories);

    function loadDirectories(response) {	
        if (response) {
	       $scope.directory=response;
	console.log($scope.directory);	
        }
        $scope.waitMessage = null;
    }

    $scope.save= function (){
    
	SwitchFactory.add($scope.directory).success(function (response) {
	
	$scope.message =response;
	
	}
	).error(function(data, status, headers, config) {
	      // called asynchronously if an error occurs
	$scope.message =response;
	$scope.message =data;
		        });
	

	
    };
});
app.controller('SwitchCtrl', function SwitchCtrl($scope,SwitchFactory,$http) {
   
    $scope.loading = true;
    $scope.addMode = false;
    $scope.success = false;
    $scope.param1 ="";
    $scope.param2 ="";
    $scope.percentage = 0;
    $scope.waitMessage = "wait message";
    $scope.directorylist={};

    $http.post("http://194.90.90.222:8080/api/getdirectorylist","{}").success(loadDirectories);

    function loadDirectories(response) {	
	console.log(response);	
        if (response) {
            if (response.message) $scope.message = response.message;
//      
	       $scope.directorylist=response;
		
        }
        $scope.waitMessage = null;
    }

    
    $scope.closeDialog = function () {
    $scope.message = null;
    };
	
    $scope.makeUrl = function(id) {
          return  "http://194.90.90.222:8080/directory.htm?id="+id;
	      }
    
    $scope.save = function () {
        $scope.waitMessage = "ok";
//	alert("js save");
       // var Polyg = this.Polygon;
       SwitchFactory.add($scope.switch).success(function (response) {
            if (response) {
                    $scope.message = response;
                    $scope.success = true;
                    $scope.switch = angular.copy($scope.switch);
            }
            $scope.waitMessage = null;
        });
    };
    });
